package com.notice.controller;

import com.notice.service.NoticeService;
import com.order.hit.crossover.platform.common.utils.PFResponse;
import com.order.hit.crossover.platform.common.bean.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Notice")
public class NoticeController
{
    @Autowired
    @Qualifier("NoticeServiceImpl")
    private NoticeService noticeService;

    @GetMapping("/selectbyNoticeId/{noticeId}")
    public PFResponse selectbyNoticeId(@PathVariable("noticeId")Long noticeId) {
        PFResponse resp = new PFResponse();

        resp.code(200).message("查询成功！");
        resp.data(noticeService.selectbyNoticeId(noticeId));

        return resp;
    }

    @GetMapping("/selectOfStore/{storeId}")
    public PFResponse selectOfStore(@PathVariable("storeId")String storeId) {
        PFResponse resp = new PFResponse();

        resp.code(200);
        resp.message("查询成功！");
        resp.data(noticeService.selectbyStoreId(storeId, 0));

        return resp;
    }

    @GetMapping("/selectUnreadOfStore/{storeId}")
    public PFResponse selectUnreadOfStore(@PathVariable("storeId")String storeId) {
        PFResponse resp = new PFResponse();

        resp.code(200);
        resp.message("查询成功！");
        resp.data(noticeService.selectUnreadOfStore(storeId, 0));

        return resp;
    }

    @GetMapping("/selectReadOfStore/{storeId}")
    public PFResponse selectReadOfStore(@PathVariable("storeId")String storeId) {
        PFResponse resp = new PFResponse();

        resp.code(200);
        resp.message("查询成功！");
        resp.data(noticeService.selectReadOfStore(storeId, 0));

        return resp;
    }

    @GetMapping("/selectOfCustomer/{customerId}")
    public PFResponse selectOfCustomer(@PathVariable("customerId")String customerId) {
        PFResponse resp = new PFResponse();

        resp.code(200);
        resp.message("查询成功！");
        resp.data(noticeService.selectbyStoreId(customerId, 1));

        return resp;
    }

    @GetMapping("/selectUnreadOfCustomer/{customerId}")
    public PFResponse selectUnreadOfCustomer(@PathVariable("customerId")String customerId) {
        PFResponse resp = new PFResponse();

        resp.code(200);
        resp.message("查询成功！");
        resp.data(noticeService.selectUnreadOfStore(customerId, 1));

        return resp;
    }

    @GetMapping("/selectReadOfCustomer/{customerId}")
    public PFResponse selectReadOfCustomer(@PathVariable("customerId")String customerId) {
        PFResponse resp = new PFResponse();

        resp.code(200);
        resp.message("查询成功！");
        resp.data(noticeService.selectReadOfStore(customerId, 1));

        return resp;
    }

    @PostMapping("/add")
    public PFResponse add(@RequestBody Notice notice) {
        PFResponse resp = new PFResponse();
        String message = "";
        int code = 0;

        try{
            noticeService.add(notice);
            message = "添加成功！";
            code = 200;

        }catch(Exception e) {
            e.printStackTrace();
            message = "添加失败！";
            code = 500;
        }

        resp.code(code).message(message);
        return resp;
    }

    @PostMapping("/update")
    public PFResponse update(@RequestBody Notice notice) {
        PFResponse resp = new PFResponse();
        String message = "";
        int code = 0;

        try{
            noticeService.update(notice);
            message = "修改成功！";
            code = 200;

        }catch(Exception e) {
            e.printStackTrace();
            message = "修改失败！";
            code = 500;
        }

        resp.code(code).message(message);
        return resp;
    }

    @PostMapping("/updatestate/{noticeId}")
    public PFResponse updatestate(@PathVariable("noticeId")Long noticeId) {
        PFResponse resp = new PFResponse();
        String message = "";
        int code = 0;

        try{
            noticeService.updatestate(noticeId);
            message = "修改状态成功！";
            code = 200;

        }catch(Exception e) {
            e.printStackTrace();
            message = "修改状态失败！";
            code = 500;
        }

        resp.code(code).message(message);
        return resp;
    }

    @PostMapping("/delete/{noticeId}")
    public PFResponse delete(@PathVariable("noticeId")Long noticeId) {
        PFResponse resp = new PFResponse();
        String message = "";
        int code = 0;

        try{
            noticeService.deletebyNoticeId(noticeId);
            message = "删除成功！";
            code = 200;

        }catch(Exception e) {
            e.printStackTrace();
            message = "删除失败！";
            code = 500;
        }

        resp.code(code).message(message);
        return resp;
    }

}
